﻿<UserControl 
    xmlns:views="clr-namespace:Acme.MVVM.Scenarios.Views"
    x:Class="Acme.MVVM.Scenarios.Views.ListBoxItemExecuteCommandView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    mc:Ignorable="d" 
    d:DesignHeight="400" d:DesignWidth="426">
    <Grid d:DataContext="{d:DesignInstance views:ListBoxItemExecuteCommandViewModel, IsDesignTimeCreatable=True}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <TextBlock Margin="6" Text="Demonstrates ListBoxItems executing a command on the view's view model." FontSize="24" TextWrapping="Wrap" Grid.ColumnSpan="2" />

        <TextBlock Grid.Row="1" Margin="6" Text="There are times when developers want to seperate selection from the ListBox's selection model, this is one way to accomplish the task." FontSize="16" TextWrapping="Wrap" Grid.ColumnSpan="2" />

        <ListBox x:Name="lbPeople" Grid.Row="2" ItemsSource="{Binding Path=People}" Margin="6">
            <ListBox.Resources>
                <Style TargetType="ListBoxItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                </Style>
            </ListBox.Resources>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <DockPanel Margin="3,4">
                        <Button 
                            DockPanel.Dock="Right" Content="edit" 
                            Command="{Binding ElementName=lbPeople, Path=DataContext.ViewPersonCommand}" CommandParameter="{Binding}"/>
                        <TextBlock Text="{Binding Path=FullName}" />
                    </DockPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <Grid Margin="6" Grid.Row="2" Grid.Column="1" DataContext="{Binding Path=SelectedPerson}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.Resources>
                <Style TargetType="TextBlock">
                    <Setter Property="Margin" Value="3,6"/>
                </Style>
            </Grid.Resources>
            
            <TextBlock Text="Selected Person" FontSize="14" FontWeight="Bold" Grid.ColumnSpan="2" />

            <TextBlock Grid.Column="0" Grid.Row="1" Text="Id" />
            <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Path=Id}" />

            <TextBlock Grid.Column="0" Grid.Row="2" Text="First Name" />
            <TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding Path=FirstName}" />

            <TextBlock Grid.Column="0" Grid.Row="3" Text="Last Name" />
            <TextBlock Grid.Column="1" Grid.Row="3" Text="{Binding Path=LastName}" />

        </Grid>
    </Grid>
</UserControl>
